-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.c
More file actions
36 lines (30 loc) · 780 Bytes
/
Solution.c
File metadata and controls
36 lines (30 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
void findPairs(int arr[], int n, int target) {
int found = 0;
printf("Pairs with sum %d:\n", target);
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] + arr[j] == target) {
printf("(%d, %d)\n", arr[i], arr[j]);
found = 1;
}
}
}
if (!found) {
printf("No pairs found.\n");
}
}
int main() {
int n, target;
printf("Enter the size of the array: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements of the array: ", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
printf("Enter the target sum: ");
scanf("%d", &target);
findPairs(arr, n, target);
return 0;
}